package mamma.dao;

import mamma.common.MybatisConfig;
import mamma.vo.BabyInfoVo;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class sanghyoDao {
	private SqlSessionFactory factory;
	
	public sanghyoDao(){
		factory = MybatisConfig.getSqlSessionFactory();
	}
	
	// insert baby (at first time)
	public void insertBaby(BabyInfoVo babyInfo) {
		SqlSession ss = factory.openSession();
		ss.insert("sanghyo.insertBaby", babyInfo);
		ss.commit();
		
		int babyNum = ss.selectOne("sanghyo.selectBaby", babyInfo);
		ss.commit();
		babyInfo.setBabynum(babyNum);
		
		ss.insert("sanghyo.insertBabyInfo", babyInfo);
		ss.commit();	
		ss.close();
	}
	
/*	// insert babyInfo
	public void insertBabyInfo(BabyInfoVo babyInfo) {
		SqlSession ss = factory.openSession();
		ss.insert("sanghyo.insertBabyInfo", babyInfo);
		ss.commit();	
		ss.close();
	}*/
	
	//select baby
	public BabyInfoVo selectBaby(BabyInfoVo baby) {
		SqlSession ss = factory.openSession();
		BabyInfoVo tempVo = ss.selectOne("sanghyo.selectBaby", baby);
		
		return tempVo;
		
	}
	
}
